# -*- coding: utf-8 -*-

import json

# import msgpack
# from loguru import logger
from kafka import KafkaProducer


def kfk_produce_1():
    """
        发送 json 格式数据
    :return:
    """
    producer = KafkaProducer(
        bootstrap_servers='192.168.0.195:9092',
        value_serializer=lambda v: json.dumps(v).encode('utf-8'),
    )
    for i in range(10):
        producer.send('test-kafka', {f'key{i}': f'value{i}'})


if __name__ == '__main__':
    kfk_produce_1()
